package com.service.bean.signal;

import java.sql.Timestamp;
import java.text.DecimalFormat;
import java.text.MessageFormat;
import java.util.Date;

import com.service.calculate.vehicle.IDCreator;



public class GpsSignal implements Comparable<GpsSignal> {
	
	public GpsSignal(){
		this.signalId = IDCreator.getSignalId();
	}
	
	@Override
	public int compareTo(GpsSignal o) {
		return this.gpsTime.after(o.gpsTime) ? 1 : -1;
	}
	
	public String signalId;
	// ---------------------以下为基础值--------------------------
	/**
	 * GPS时间
	 */
	public Date gpsTime;
	/**
	 * GPS经度
	 */
	public double lng;
	/**
	 * GPS纬度
	 */
	public double lat;
	/**
	 * GPS速度
	 */
	public double speed;
	/**
	 * 脉冲速度
	 */
	public double speed2;
	/**
	 * 航向
	 */
	public double direction;
	/**
	 * GPS里程
	 */
	public double curMile;
	/**
	 * 脉冲里程
	 */
	public double curMile2;
	/**
	 * 车辆类型
	 */
	public int equipmentType;
	/**
	 * 油位高度
	 */
	public double oilHeight;		
	/**
	 * 油位百分比
	 */
	public double oilAmt;
	/**
	 * 油位百分比2
	 */
	public double oilAmt2;
	/**
	 * 油位百分比3
	 */
	public double oilAmt3;
	/**
	 * 主发转速
	 */
	public double majSpeed;
	/**
	 * 副发转速
	 */
	public double subSpeed;
	/**
	 * 扫盘转速
	 */
	public double discSpeed;
	/**
	 * 扫盘转速2
	 */
	public double discSpeed2;
	/**
	 * 臭味值
	 */
	public double smellAmt;
	/**
	 * 可回收垃圾
	 */
	public double recycleAmt;
	/**
	 * 不可回收垃圾
	 */
	public double notRecycleAmt;
	/**
	 * 状态位原始值
	 */
	public long statusValue;
	/**
	 * 开关状态原始值
	 */
	public long switchValue;
	/**
	 * 故障状态原始值
	 */
	public long hitchValue;
	/**
	 * 输出状态原始值
	 */
	public long outputValue;
	/**
	 * 数据区
	 */
	public String rawData;
	// ---------------------以下为状态值--------------------------
	/**
	 * ACC状态
	 */
	public int accStatus;
	/**
	 * 加水状态
	 */
	public int waterStatus;
	/**
	 * 垃圾倾倒状态
	 */
	public int dumpStatus;
	/**
	 * 污水状态
	 */
	public int sewageStatus;
	/**
	 * 扫盘状态
	 */
	public int plateStatus;
	/**
	 * 吸嘴状态
	 */
	public int nozzleStatus;
	/**
	 * 洒水状态
	 */
	public int wateringStatus;
	/**
	 * 垃圾箱状态
	 */
	public int binStatus;
	/**
	 * 填装箱状态
	 */
	public int stuffStatus;
	/**
	 * 取力器状态
	 */
	public int strengthStatus;
	/**
	 * 电池状态
	 */
	public int batteryStatus;
	/**
	 * 定位状态
	 */
	public int gpsStatus;
	/**
	 * GPS天线状态
	 */
	public int gpsAirStatus;
	/**
	 * GPS服务状态
	 */
	public int serviceStatus;
	/**
	 * 设置状态
	 */
	public int configStatus;
	/**
	 * 锁车状态
	 */
	public int lockStatus;
	/**
	 * 输出状态1
	 */
	public int outPut0;
	/**
	 * 输出状态2
	 */
	public int outPut1;
	// ---------------------以下为计算值--------------------------
	/**
	 * 今日GPS里程
	 */
	public double todayMile;
	/**
	 * 今日脉冲里程
	 */
	public double todayMile2;
	/**
	 * GPS总里程
	 */
	public double totalMile;
	/**
	 * 脉冲总里程
	 */
	public double totalMile2;
	/**
	 * 百度经度
	 */
	public double baiduLng;
	/**
	 * 百度纬度
	 */
	public double baiduLat;
	/**
	 * 百度街道
	 */
	public String baiduStreet;
	/**
	 * 百度详细地址
	 */
	public String baiduLocation;
	/**
	 * 海拔
	 */
	public int heightAmt;
	/**
	 * 油量
	 */
	public double oilAmtCal;
	/**
	 * 油量1
	 */
	public double oilAmtCal2;
	/**
	 * 油量2
	 */
	public double oilAmtCal3;
	/**
	 * 工作状态
	 */
	public int isInWork;
	/**
	 * 非工作状态
	 */
	public int IsOutWork;
	// ---------------------以下为预留值--------------------------
	/**
	 * 预留2.x版本后为空
	 */
	public String otherValue;
	/**
	 * 预留2.x版本后为空
	 */
	public String otherValue2;
	/**
	 * 预留3.x版本垃圾称重
	 */
	public String rfid;
	// ---------------------以下为附加值--------------------------
	/**
	 * 命令字
	 */
	public String cmdTitle;
	/**
	 * GPS编号
	 */
	public String gpsNo;
	/**
	 * 车辆编号
	 */
	public String equipmentId;
	/**
	 * 公司编号
	 */
	public String companyCode;
	// ---------------------以下为标识值--------------------------
	/**
	 * 是否已转换百度坐标
	 */
	public int isPosition;
	/**
	 * 是否已获取百度地址
	 */
	public int isLocation;
	/**
	 * 是否已设置报警
	 */
	public int isHandleAlarm;
	/**
	 * 是否已设置工作状态
	 */
	public int isWorkHandle;
	/**
	 * 是否已设置加水状态
	 */
	public int isWaterHandle;
	/**
	 * 是否已补点
	 */
	public int isLineHandle;
	/**
	 * 是否有报警
	 */
	public int hasAlarm;

	/**
	 * 车辆当前所在区域 若车辆不在规划区域中，则该值为null
	 */
	public String areaId;
	
	// ---------------------以下为状态位解析后的值--------------------------
	/**
	 * 当前方位 0：南纬 1：北纬
	 */
	public int directionSN;
	/**
	 * 当前方位 0：西经 1：东经
	 */
	public int directionEW;
	/**
	 * 0:未接电源充电 1:已接电源充电
	 */
	public int connectPower;
	/**
	 * 数据类型 0：历史数据 1：实时数据
	 */
	public int dataTypes;
	/**
	 * 设备故障 0：GPS天线正常 1：GPS天线断开
	 */
	public int terminalFault;
	/**
	 * 0：输出12V正常 1：输出12V短路
	 */
	public int output12vStatus;
	/**
	 * 使用状态 0：正常 1：欠费
	 */
	public int arrearsStatus;
	
	// ---------------------以下为开关位解析后的值--------------------------
	/**
	 * 液压油位是否低于预警值
	 */
	public int isHydOilThreshold;
	/**
	 * 是否加水中
	 */
	public int isWaterAdding;
	/**
	 * 水是否加满
	 */
	public int isWaterFull;
	/**
	 * 是否垃圾倾倒中 
	 */
	public int isWasteDumping;
	/**
	 * 污水是否已满
	 */
	public int isSewageFull;
	/**
	 * 是否排污中
	 */
	public int isSewageEmission;
	/**
	 * 扫盘是否放下
	 */
	public int isBroomDown;
	/**
	 * 扫盘2是否放下
	 */
	public int isBroomDown2;
	/**
	 * 吸嘴是否放下
	 */
	public int isNozzleDown;
	/**
	 * 是否洒水中
	 */
	public int isWatering;
	/**
	 * 疏通传感器是否打开
	 */
	public int isDredgorOpen;
	/**
	 * 取力器状态
	 */
	public int ptoStatus;
	/**
	 * 水流喷头1是否打开
	 */
	public int isWaterNozzleOpen;
	/**
	 * 水流喷头2是否打开
	 */
	public int isWaterNozzleOpen2;
	/**
	 * 水流喷头3是否打开
	 */
	public int isWaterNozzleOpen3;
	/**
	 * 高压喷杆是否打开
	 */
	public int isLanceOpen;
	/**
	 * 垃圾箱是否放下
	 */
	public int isTrashDown;
	
	// ---------------------以下为故障位解析后的值--------------------------
	/**
	 * 臭味超标
	 */
	public int odorExc;
	/**
	 * 油位低
	 */
	public int oilExc;
	/**
	 * 工作时（见工作状态定义表）行驶超速
	 */
	public int speedExc;
	/**
	 * 液压油位低
	 */
	public int hydOilExc;
	/**
	 * 副发转速超标
	 */
	public int auxiMotorSpeedExc;
	/**
	 * 副发转速超标
	 */
	public int waterNotFull;
	/**
	 * 扫盘不下落
	 */
	public int broomCanNotDown;
	/**
	 * 扫盘转速异常
	 */
	public int broomSpeedExc;
	/**
	 * 吸嘴不下落
	 */
	public int nozzleCanNotDown;
	/**
	 * 扫盘开启无洒水
	 */
	public int broomOpenNoWatering;
	/**
	 * 水流传感器异常
	 */
	public int waterNozzleExc;
	/**
	 * 发动机转速超速
	 */
	public int motorSpeedExc;
	/**
	 * 污水排放
	 */
	public int sewageEmission;
	/**
	 * 污水满
	 */
	public int sewageFull;
	/**
	 * 油位突变报警
	 */
	public int oilMutation;
	/**
	 * 垃圾箱（填充箱）未放下
	 */
	public int trashNotDown;
	
	/**
	 * 油位变化量
	 */
	public double oilChange;	
	/**
	 * gps里程变化量
	 */
	public double mileChange;
	/**
	 * 停车时长的累计
	 */
	public long sumStopTime;	
	/**
	 * 工作状态中，速度为0的时长的累计
	 */
	public long sumWorkStopTime;
	
	/**
	 * 最新Gps数据中的油量
	 */
	public double realOilCal;
	/**
	 * 洒水量
	 */
	public double sprinklingWater;
	/**
	 * 持续时间
	 */
	public double durationtime = 0;

	@SuppressWarnings("deprecation")
	public Object[] getAll() {
		DecimalFormat df = new DecimalFormat("0.00");
		Object[] array = new Object[67];
		array[0] = "'" + this.gpsNo + "'";
		array[1] = this.gpsTime == null ? this.gpsTime : "'" + new Timestamp(this.gpsTime.getTime()) + "'";
		array[2] = String.valueOf(this.lng);
		array[3] = String.valueOf(this.lat);
		array[4] = String.valueOf(this.speed);
		array[5] = String.valueOf(this.direction);
		array[6] = String.valueOf(this.curMile);
		array[7] = String.valueOf(this.totalMile);
		array[8] = String.valueOf(this.todayMile);
		array[9] = this.gpsStatus;
		array[10] = String.valueOf(this.equipmentType);
		array[11] = String.valueOf(this.oilAmt);
		array[12] = String.valueOf(this.majSpeed);
		array[13] = String.valueOf(this.subSpeed);
		array[14] = String.valueOf(this.discSpeed);
		array[15] = String.valueOf(this.smellAmt);
		array[16] = String.valueOf(this.recycleAmt);
		array[17] = String.valueOf(this.notRecycleAmt);
		array[18] = String.valueOf(this.statusValue);
		array[19] = String.valueOf(this.switchValue);
		array[20] = String.valueOf(this.hitchValue);
		array[21] = String.valueOf(this.outputValue);
		array[22] = this.accStatus;
		array[23] = this.waterStatus;
		array[24] = this.dumpStatus;
		array[25] = this.sewageStatus;
		array[26] = this.plateStatus;
		array[27] = this.nozzleStatus;
		array[28] = this.wateringStatus;
		array[29] = this.binStatus;
		array[30] = this.stuffStatus;
		array[31] = this.serviceStatus;
		array[32] = String.valueOf(this.baiduLng);
		array[33] = String.valueOf(this.baiduLat);
		array[34] = baiduLocation==null?baiduLocation:"'"+baiduLocation+"'";
		array[35] = this.isPosition;
		array[36] = this.isLocation;
		array[37] = this.isHandleAlarm;
		array[38] = String.valueOf(this.curMile2);
		array[39] = String.valueOf(this.totalMile2);
		array[40] = String.valueOf(this.todayMile2);
		array[41] = "'" + this.companyCode + "'";
		array[42] = this.lockStatus;
		array[43] = String.valueOf(this.speed2);
		array[44] = String.valueOf(this.discSpeed2);
		array[45] = rawData == null ? rawData : "'"+rawData + "'";
		array[46] = this.isWorkHandle;
		array[47] = this.strengthStatus;
		array[48] = String.valueOf(this.oilAmt2);
		array[49] = String.valueOf(this.oilAmt3);
		array[50] = this.isInWork;
		array[51] = cmdTitle == null ? cmdTitle : "'" + this.cmdTitle + "'";
		array[52] = String.valueOf(this.oilAmtCal);
		array[53] = String.valueOf(this.heightAmt);
		array[54] = this.outPut0;
		array[55] = this.outPut1;
		array[56] = this.batteryStatus;
		array[57] = this.gpsAirStatus;
		array[58] = this.configStatus;
		array[59] = "'" + this.equipmentId + "'";
		array[60] = String.valueOf(this.oilAmtCal2);
		array[61] = String.valueOf(this.oilAmtCal3);
		array[62] = this.isWaterHandle;
		array[63] = baiduStreet == null ? baiduStreet : "'" + baiduStreet + "'";
		array[64] = "'"  + this.signalId + "'";
		array[65] = this.gpsTime.getMonth()+1;
		array[66] = df.format(this.sprinklingWater);
		return array;
	}
	
	public Object[] getAllForJson() {
		Object[] array = getAll();
		array[0] = "\"" + this.gpsNo + "\"";
		array[1] = this.gpsTime == null ? this.gpsTime : "\"" + new Timestamp(this.gpsTime.getTime()) + "\"";		
		array[34] = baiduLocation == null ? "\"\"" : "\"" + baiduLocation + "\"";
		array[41] = "\"" + this.companyCode + "\"";
		array[45] = rawData == null ? "\"\"" : "\"" + rawData + "\"";
		array[51] = cmdTitle == null ? "\"\"" : "\"" + this.cmdTitle + "\"";
		array[59] = "\"" + this.equipmentId + "\"";
		array[63] = baiduStreet == null ? "\"\"" : "\"" + baiduStreet + "\"";
		array[64] = "\""  + this.signalId + "\"";
		return array;
	}
	
	/**
	 * 转换成Json格式
	 */
	@Override
	public String toString() {
		StringBuilder sBuilder = new StringBuilder();

		sBuilder.append("\"GPSNO\":{0},");
		sBuilder.append("\"GPSTime\":{1},");
		sBuilder.append("\"Lng\":{2},");
		sBuilder.append("\"Lat\":{3},");
		sBuilder.append("\"Speed\":{4},");
		sBuilder.append("\"Direction\":{5},");
		sBuilder.append("\"CurMile\":{6},");
		sBuilder.append("\"TotalMile\":{7},");
		sBuilder.append("\"TodayMile\":{8},");
		sBuilder.append("\"GPSStatus\":{9},");
		sBuilder.append("\"EquipmentType\":{10},");
		sBuilder.append("\"OilAmt\":{11},");
		sBuilder.append("\"MajSpeed\":{12},");
		sBuilder.append("\"SubSpeed\":{13},");
		sBuilder.append("\"DiscSpeed\":{14},");
		sBuilder.append("\"SmellAmt\":{15},");
		sBuilder.append("\"RecycleAmt\":{16},");
		sBuilder.append("\"NotRecycleAmt\":{17},");
		sBuilder.append("\"StatusValue\":{18},");
		sBuilder.append("\"SwitchValue\":{19},");
		sBuilder.append("\"HitchValue\":{20},");
		sBuilder.append("\"OutputValue\":{21},");
		sBuilder.append("\"AccStatus\":{22},");
		sBuilder.append("\"WaterStatus\":{23},");
		sBuilder.append("\"DumpStatus\":{24},");
		sBuilder.append("\"SewageStatus\":{25},");
		sBuilder.append("\"PlateStatus\":{26},");
		sBuilder.append("\"NozzleStatus\":{27},");
		sBuilder.append("\"WateringStatus\":{28},");
		sBuilder.append("\"BinStatus\":{29},");
		sBuilder.append("\"StuffStatus\":{30},");
		sBuilder.append("\"ServiceStatus\":{31},");
		sBuilder.append("\"BaiduLng\":{32},");
		sBuilder.append("\"BaiduLat\":{33},");
		sBuilder.append("\"BaiduLocation\":{34},");
		sBuilder.append("\"IsPosition\":{35},");
		sBuilder.append("\"IsLocation\":{36},");
		sBuilder.append("\"IsHandleAlarm\":{37},");
		sBuilder.append("\"CurMile2\":{38},");
		sBuilder.append("\"TotalMile2\":{39},");
		sBuilder.append("\"TodayMile2\":{40},");
		sBuilder.append("\"CompanyCode\":{41},");
		sBuilder.append("\"LockStatus\":{42},");
		sBuilder.append("\"Speed2\":{43},");
		sBuilder.append("\"DiscSpeed2\":{44},");
		sBuilder.append("\"rawData\":{45},");
		sBuilder.append("\"IsWorkHandle\":{46},");
		sBuilder.append("\"StrengthStatus\":{47},");
		sBuilder.append("\"OilAmt2\":{48},");
		sBuilder.append("\"OilAmt3\":{49},");
		sBuilder.append("\"IsInWork\":{50},");
		sBuilder.append("\"CmdTitle\":{51},");
		sBuilder.append("\"OilAmtCal\":{52},");
		sBuilder.append("\"HeightAmt\":{53},");
		sBuilder.append("\"OutPut0\":{54},");
		sBuilder.append("\"OutPut1\":{55},");
		sBuilder.append("\"BatteryStatus\":{56},");
		sBuilder.append("\"GPSAirStatus\":{57},");
		sBuilder.append("\"ConfigStatus\":{58},");
		sBuilder.append("\"EquipmentId\":{59},");
		sBuilder.append("\"OilAmtCal2\":{60},");
		sBuilder.append("\"OilAmtCal3\":{61},");
		sBuilder.append("\"IsWaterHandle\":{62},");
		sBuilder.append("\"BaiduStreet\":{63},");
		sBuilder.append("\"SignalId\":{64},");
		sBuilder.append("\"SignalMonth\":{65},");
		sBuilder.append("\"SprinklingWater\":{66},");
		sBuilder.append("\"OilAmtChange\":"+ String.valueOf(this.oilChange) +",");
		sBuilder.append("\"MileChange\":" +String.valueOf(this.mileChange) + ",");
		sBuilder.append("\"StopTime\":" + String.valueOf(this.sumStopTime) +",");
		sBuilder.append("\"WorkStopTime\":" + String.valueOf(this.sumWorkStopTime) + ",");
		sBuilder.append("\"IsOutWork\":" + String.valueOf(this.IsOutWork) + "");

		return MessageFormat.format(sBuilder.toString(),this.getAllForJson());
	}
}
